package com.zzw.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RefreshScope
public class NacosConfigClientController {

    /**
     * 1.client 会拉取nacos server的e-commerce-nacos-config-client-dev.yaml
     * config:
     *     ip: "localhost"
     *     name: "zzw"
     *  2.@Value("${config.ip}") 会将config.ip 赋给 configIp
     */
    @Value("${config.ip}")
    private String configIp;

    @Value("${config.name}")
    private String configName;

    @GetMapping("nacos/config/ip")
    public String getIp() {
        log.info("获取到的ip地址: {}", configIp);
        return configIp;
    }

    @GetMapping("nacos/config/name")
    public String getName() {
        log.info("获取到的名称: {}", configName);
        return configName;
    }
}
